/*
Package user
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2024/3/1 17:14
@File     : user_hooks.go
@Project  : gohub
@Desc     :
*/
package user

import (
	"gohub/pkg/hash"
	"gorm.io/gorm"
)

// BeforeSave 创建或更新时对未加密密码加密
func (userModel *User) BeforeSave(tx *gorm.DB) (err error) {
	if !hash.BcryptIsHashed(userModel.Password) {
		userModel.Password = hash.BcryptHash(userModel.Password)
	}
	return
}
